import { defineStore } from 'pinia'

export const useList = defineStore('list', {
    persist: {
        enabled: true, //开启数据持久化
        strategies: [
            {
                key: "details",
                storage: sessionStorage
            }
        ]
    },
    state: () => {
        return {
            //面包屑数据
            tabList: [
                {
                    path: "/",
                    name: "Main",
                    label: "首页",
                    icon: "house",
                    url: "Home",
                },
            ],
            //任务列表数据
            tableDataL: [],
            //detail数据
            details: [],
            //Task 搜索数据
            seaForm: {
                inputTitle: '',
                state: '',
                type: '',
                priority: '',
                deadline: '',
                inputOperator: '',
            },
            //Group 级联数据
            cascadeDate: [],

            token: null,

        }
    },
    actions: {

        updateToken(val) {
            this.token = val
          },

        //更新面包屑数据
        selectMenu(val) {
            // 状态量
            const index = { status: true }
            if (val.name !== 'Main') {
                //判断是否有重复添加的数据
                this.tabList.forEach(element => {
                    if (element.name === val.name) {
                        index.status = false
                    }
                });
                // const index = this.tabList.findIndex(item => item.path === val.item )
                // console.log('index',index)
                if (index.status) {
                    this.tabList.push(val)
                }
            }
        },
        //更新任务列表数据 
        updateTableL(val) {
           
            this.tableDataL = val

        },
        //更新 details 数据
        upDetail(val) {
            console.log(val,'9999999999')
            this.details = val
        },
        //更新 级联数据
        upCascade(val) {
            this.cascadeDate = val
            console.log("val",this.cascadeDate)
        }
    }
})